/**
 * @author 汪孟苹
 */
define(['jquery','template','scprit/department/view/template/physicalExaminationAnalysisReport.tpl.js'],function($,template,tpl){
	var temperature = {};
	var drawtemperatureList = function(data){
		return template("tpl_temperature_list",data);
	}
	var drawtemperatureDetailInfo = function(data){
		return template("tpl_temperature_datailInfo",data);
	}
	var drawUserinfo = function(data){
		return template("tpl_userinfo2",data);
	}
	var temperatureListData = function(list,bodytemperatureId){
		var arr = [];
		for(var i=0;i<list.length;i++){
			arr[i] = list[i];
			if(arr[i].bodytemperatureId == bodytemperatureId){
				arr[i].active = true;
			}else{
				arr[i].active = false;
			}
		}
		return arr;
	}
	var temperatureDetailInfoData = function(list){
		var arr = [];
		var minute = parseInt(list.timeLong / 60);
		var second = parseInt(list.timeLong % 60);
		list.timeLong = minute+'分'+second+'秒';
		list.userType = list.userType=="01"? "早产儿":"正常";
		var time1 = list.testTime.split(' ')[0];
		var mouth = time1.split('-')[1];
		var day = time1.split('-')[2];
		var time2 = list.testTime.split(' ')[1];
		var hour = time2.split(':')[0];
		var minute = time2.split(':')[1];
		list.testTime = mouth+"月"+day+"日 "+hour+":"+minute;
		arr.push(list);
		return arr;
	}
	temperature.lineData = function(list){
		var arrTime = [];
        var arrTemp = [];
        for (var i = 0; i < list.length; i++) {
            arrTemp.push(list[i].bodyTemperature);
            arrTime.push(list[i].testTime.substr(11));
        }
        return {arrTime:arrTime,arrTemp:arrTemp};
	}
	temperature.userInfoInit = function(options){
		$("#"+options.id).html(tpl.init3());
		var h = drawUserinfo(options.list);
		$("#"+options.id).html(h);
	}
	temperature.listInit = function(options){
		var data = {
			rows: temperatureListData(options.list,options.bodytemperatureId)
		}
		$("#"+options.id).html(tpl.init1());
		var h = drawtemperatureList(data);
		$("#"+options.id).html(h);
	}
	temperature.DetailInfoInit = function(options){
		var data = {
			rows: temperatureDetailInfoData(options.list)
		}
		$("#"+options.id).html(tpl.init2());
		var h = drawtemperatureDetailInfo(data);
		$("#"+options.id).html(h);
	}
	temperature.tempalarm= function(tempalarmTop,perTop){
		var arr = [];
		var arrLabel = ['<='+tempalarmTop,'>'+tempalarmTop];
		var arrDots = ['   ...........  ','     ...........   '];
		var perTopNo = (100 - perTop) + "%";
		var perTopYes = perTop + "%";
		var arrPercent = [perTopNo,perTopYes];
		for (var i = 0; i < arrLabel.length; i++) {
			for (var j = 0; j < arrDots.length; j++) {
				if(i == j){
					arr[i] = arrLabel[i] + arrDots[j];
				}
			}
			arr[i] = arr[i] + arrPercent[i];
		}
        return arr;
	}
	temperature.timeLong=function(timeLong){
		var d=parseInt(timeLong/(3600*24));
		var h=parseInt(timeLong/3600);
		var m=parseInt((timeLong%3600)/60);
		var s=parseInt((timeLong%3600)%60);
		var duration;
		if(d>=1){
			if(h>=1){
				if(m>=1){
					if(s>=1){
						duration=d+"天"+h+"小时"+m+"分"+s+"秒";
					}else{
						duration=d+"天"+h+"小时"+m+"分";
					}
				}else{
					if(s>=1){
						duration=d+"天"+h+"小时"+s+"秒";
					}else{
						duration=d+"天"+h+"小时";
					}
				}
			}else{
				if(m>=1){
					if(s>=1){
						duration=d+"天"+m+"分"+s+"秒";
					}else{
						duration=d+"天"+m+"分";
					}
				}else{
					if(s>=1){
						duration=d+"天"+s+"秒";
					}else{
						duration=d+"天";
					}
				}
			}
		}else{
			if(h>=1){
				if(m>=1){
					if(s>=1){
						duration=h+"小时"+m+"分"+s+"秒";
					}else{
						duration=h+"小时"+m+"分";
					}
				}else{
					if(s>=1){
						duration=h+"小时"+s+"秒";
					}else{
						duration=h+"小时";
					}
				}
			}else{
				if(m>=1){
					if(s>=1){
						duration=m+"分"+s+"秒";
					}else{
						duration=m+"分";
					}
				}else{
					if(s>=1){
						duration=s+"秒";
					}else{
						duration="暂无数据";
					}
				}
			}
		}
		return duration;
	}
	return temperature;
});